﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Pavilion.DesignerTool.ViewTools
{
    public class ObjectPropertyItem : PropertyItemBase
    {
        public override string PropertyName { get { return PropertyDescriptor.DisplayName; } set { } }
        public override object PropertyValue { get { return PropertyDescriptor.GetValue(AssociatedItem); } set { SetPropertyValue(value); } }
        public override object AssociatedItem { get; set; }
        public override System.Windows.FrameworkElement FrameworkElement { get; set; }
        public PropertyDescriptor PropertyDescriptor { get; set; }

        public ObjectPropertyItem(PropertyDescriptor propertyDescriptor, object item)
        {
            this.PropertyDescriptor = propertyDescriptor;
            this.AssociatedItem = item;

            LoadDefaultFrameworkElement();
        }

        protected virtual void SetPropertyValue(object value)
        {
            PropertyDescriptor.SetValue(AssociatedItem, value);
            LoadDefaultFrameworkElement();
        }
    }
}
